package xnet.Message
{
	import flash.utils.ByteArray;
	import flash.utils.describeType;

	public class MessageBase extends Object implements ISokcetMessage
	{
		/**临时存储socket数据**/
		private var _byteArray:ByteArray ;
		/**指令集类型**/
		private var _type:int;
		/**指令集工厂**/
		private var _socketCommand:ISokcetMessage;
		 
		
		public function MessageBase() 
		 {
			 _byteArray = new ByteArray();
		 }

		/**写入类型数据**/
		public function write():void
		{
			//_byteArray.writeByte(_type);
		}
		/**写入类型数据**/
		public function writeint(v:int):void
		{
			_byteArray.writeByte(v);
		}
		public function writeString(v:String):void
		{
			_byteArray.writeByte(v.length);
			_byteArray.writeUTFBytes(v);
		}
		/**对接收的Socket信息进行解码**/
		public function decodeSocketData(byteArray:ByteArray):ISokcetMessage
		{
			_type = byteArray.readByte();
			return _socketCommand;
		}		
		
		public function set byteArray(value:ByteArray):void
		{
			_byteArray = value;
		}
		
		public function filtername(name:String):Boolean
		{
			if (name=="byteArray") return false;
			if (name=="socketCommand") return false;
			if (name=="type") return false;			
			return true;
		}
		public function get byteArray():ByteArray
		{
			return _byteArray;
		}
		
		public function get type():int
		{
			return _type;
		}
		
		public function set type(value:int):void
		{
			_type = value;
		}
		
		public function get socketCommand():ISokcetMessage
		{
			return _socketCommand;
		}
		
		public function set socketCommand(value:ISokcetMessage):void
		{
			_socketCommand = value;
		}
		
		public function getP():Array
		{
			var oXml:XML=describeType(this);
			
			var acc : XMLList = XMLList(oXml.child("accessor"));
			
			var arr : Array = [];
			
			for each(var propertyInfo:XML in acc)
			{
				if (filtername(propertyInfo.@name)){
					arr.push(String(propertyInfo.@name));	
				}				
			}
			
			this["UserName"]="sssss";
			
			arr.sort(Array.CASEINSENSITIVE);

			return arr;
		}
	}
}